

*###################### ###################### ###################### #
* Visa Policy and International Student Migration: Evidence from Canada 
*###################### ###################### ###################### #


**********************
* Baseline - Table 1 *
********************** 

use "$data/Finalmaster.dta", clear


preserve
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1 = e(sample)
count if sample1==1 
count if sample1==1 & aggregate_students_origin==0
estimates store r_1
restore
* India
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_I = e(sample)
count if sample1_I==1 
count if sample1_I==1 & aggregate_students_origin==0
estimates store r_2
restore 
* China
preserve
drop if Origin=="Vietnam" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_C = e(sample)
count if sample1_C==1
count if sample1_C==1 & aggregate_students_origin==0
estimates store r_3
restore
* Vietnam
preserve
drop if Origin=="China" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_V = e(sample)
count if sample1_V==1
count if sample1_V==1 & aggregate_students_origin==0
estimates store r_4
restore
esttab r_* using baseline.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace


*.......

***********
* Table 2
***********
* PSM - REG


clear all
use  "$dataPSM.dta", replace



*India / Country by Country
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store kt_1
ppmlhdfe aggregate_students_origin treatment_var [pweight=pscore_india] if sample_==1 & year>=2003 & year<=2017 ,  absorb(it jt ji) cluster(ji)
estimates store kt_2 
restore

*China / Country by Country
preserve
drop if Origin=="India" | Origin=="Vietnam"
*******************
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store kt_3
ppmlhdfe aggregate_students_origin treatment_var [pweight=pscore_china] if sample_==1 & year>=2003 & year<=2017 ,  absorb(it jt ji) cluster(ji) 
estimates store kt_4
restore

*Vietnam / Country by Country
preserve
drop if Origin=="India" | Origin=="China"
gen top_OECD = 0
*******************
replace top_OECD =1 if Origin =="Australia" | Origin =="Austria" | Origin =="Belgium" | Origin =="Canada" | Origin =="Denmark" | Origin =="Finland" | Origin =="France" | Origin =="Germany" | Origin =="Greece" | Origin =="Iceland" | Origin =="Ireland" |  Origin =="Italy" | Origin =="Japan" | Origin =="Luxembourg" | Origin =="Mexico" | Origin =="Netherlands" | Origin =="New Zealand" | Origin =="Norway" | Origin =="Portugal" | Origin =="Spain" | Origin =="Sweden" | Origin =="Switzerland" | Origin =="Turkey" | Origin =="United Kingdom" | Origin =="United States of America" |   Origin =="Czech Republic"  | Origin =="Hungary" | Origin =="South Korea" |  Origin =="Poland" | Origin =="Slovak Republic" | Origin =="England"  | Origin =="Scotland" | Origin =="Slovakia" | Origin =="Wales"
drop if top_OECD==1
*******************
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store kt_5
ppmlhdfe aggregate_students_origin treatment_var [pweight=pscore_vietnam] if sample_==1 & year>=2003 & year<=2017 ,  absorb(it jt ji) cluster(ji) 
estimates store kt_6
restore
esttab kt_* using PSM.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace



 
************
* Table 3 *
************ 


clear all
use "$dataFinalmaster.dta", clear


merge 1:1 Insitution_Code_5Digit year Origin using "$dataLagAppRate.dta"
drop if _merge==2 
drop _merge

gen Approval_Rate = (Appapproved_new/Apptotal_new)*100
ppml_panel_sg aggregate_students_origin treatment_var Approval_Rate_l1 if sample_==1 & year>=2003 & year<=2013, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
gen sample_ppml = e(sample)

* Aggregate / Only AppRate
preserve
ppml_panel_sg aggregate_students_origin Approval_Rate_l1 if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_1
restore
* Aggregate / Only Treatment Var
preserve
ppml_panel_sg aggregate_students_origin treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_2
restore
* Aggregate
preserve
ppml_panel_sg aggregate_students_origin treatment_var Approval_Rate_l1 if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_3
restore
*India / Country by Country
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppml_panel_sg aggregate_students_origin treatment_var Approval_Rate_l1 if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_4
restore 
*China / Country by Country
preserve
drop if Origin=="Vietnam" | Origin=="India"
ppml_panel_sg aggregate_students_origin treatment_var Approval_Rate_l1 if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_5
restore
*
esttab ki_* using AppRate_Control_till2013.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace
 
 
**********************
* Table 4 - Non-OECD *
**********************


use "$dataFinalmaster.dta", clear

*Dropping OECD countries
*******************
gen top_OECD = 0
*******************
replace top_OECD =1 if Origin =="Australia" | Origin =="Austria" | Origin =="Belgium" | Origin =="Canada" | Origin =="Denmark" | Origin =="Finland" | Origin =="France" | Origin =="Germany" | Origin =="Greece" | Origin =="Iceland" | Origin =="Ireland" |  Origin =="Italy" | Origin =="Japan" | Origin =="Luxembourg" | Origin =="Mexico" | Origin =="Netherlands" | Origin =="New Zealand" | Origin =="Norway" | Origin =="Portugal" | Origin =="Spain" | Origin =="Sweden" | Origin =="Switzerland" | Origin =="Turkey" | Origin =="United Kingdom" | Origin =="United States of America" |   Origin =="Czech Republic"  | Origin =="Hungary" | Origin =="South Korea" |  Origin =="Poland" | Origin =="Slovak Republic" | Origin =="England"  | Origin =="Scotland" | Origin =="Slovakia" | Origin =="Wales"

* Columns 1-4
preserve
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017 & top_OECD==0, absorb(it jt ji) cluster(ji)
gen sample1 = e(sample)
count if sample1==1 
count if sample1==1 & aggregate_students_origin==0
* 
estimates store r_1
restore
* India
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017 & top_OECD==0, absorb(it jt ji) cluster(ji)
gen sample1_I = e(sample)
count if sample1_I==1 
count if sample1_I==1 & aggregate_students_origin==0
* 
estimates store r_2
restore 
* China
preserve
drop if Origin=="Vietnam" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017 & top_OECD==0, absorb(it jt ji) cluster(ji)
gen sample1_C = e(sample)
count if sample1_C==1
count if sample1_C==1 & aggregate_students_origin==0
* 
estimates store r_3
restore
* Vietnam
preserve
drop if Origin=="China" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017 & top_OECD==0, absorb(it jt ji) cluster(ji)
gen sample1_V = e(sample)
count if sample1_V==1
count if sample1_V==1 & aggregate_students_origin==0
*
estimates store r_4
restore
esttab r_* using Control_nonOECD.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace


*List OECD
*https://www.oecd.org/about/document/ratification-oecd-convention.htm


*************************************************
* Table 5 / lag treatment effects (Santos Silva)* 
*************************************************


use "$dataFinalmaster.dta", clear


preserve
keep Insitution_Code_5Digit Origin year treatment_var
gen year_ = year-1
drop year
ren year_ year
ren treatment_var treatment_var_lag1
sort Insitution_Code_5Digit Origin year
save "C:\Users\mauro\Desktop\treatment_lag1.dta", replace
restore

preserve
keep Insitution_Code_5Digit Origin year treatment_var
gen year_ = year-2
drop year
ren year_ year
ren treatment_var treatment_var_lag2
sort Insitution_Code_5Digit Origin year
save "C:\Users\mauro\Desktop\treatment_lag2.dta", replace
restore

preserve
keep Insitution_Code_5Digit Origin year treatment_var
gen year_ = year-3
drop year
ren year_ year
ren treatment_var treatment_var_lag3
sort Insitution_Code_5Digit Origin year
save "C:\Users\mauro\Desktop\treatment_lag3.dta", replace
restore

sort Insitution_Code_5Digit Origin year 
merge Insitution_Code_5Digit Origin year using "treatment_lag1.dta"
tab _merge
drop _merge

sort Insitution_Code_5Digit Origin year 
merge Insitution_Code_5Digit Origin year using "treatment_lag2.dta"
tab _merge
drop _merge

sort Insitution_Code_5Digit Origin year 
merge Insitution_Code_5Digit Origin year using "treatment_lag3.dta"
tab _merge
drop _merge

preserve
ppmlhdfe aggregate_students_origin treatment_var treatment_var_lag1 treatment_var_lag2 treatment_var_lag3 if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1 = e(sample)
count if sample1==1 
count if sample1==1 & aggregate_students_origin==0
* 
estimates store r_1
reghdfe aggregate_students_origin treatment_var treatment_var_lag1 treatment_var_lag2 treatment_var_lag3 if sample1==1, absorb(it jt ji) cluster(ji)
estimates store r_2
restore
esttab r_* using proportional_trends.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace


***********
* Table 6 *
***********

* 


use "$dataFinalmaster.dta", clear


******* Run control group with colleges only 

replace sample_ = 0
replace sample_ = 1 if treated_list==1 | controlgroup2==1 
replace sample_ = 0 if enlargedcontrol==0
replace sample_ = 0 if controlbis==1


********
preserve
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store l_1
gen sample_ppml = e(sample)
count if aggregate_students_origin==0 & sample_ppml==1
*
restore 
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store l_2
gen sample_ppml = e(sample)
count if aggregate_students_origin==0 & sample_ppml==1
*  
restore 
preserve
drop if Origin=="Vietnam" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store l_3
gen sample_ppml = e(sample)
count if aggregate_students_origin==0 & sample_ppml==1
* 
restore 
preserve
drop if Origin=="China" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store l_4
gen sample_ppml = e(sample)
count if aggregate_students_origin==0 & sample_ppml==1
* 
restore 
esttab l_* using tab7_ddd.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace



use "$dataFinalmaster.dta", clear


***** Run control group without colleges
replace sample_ = 0
replace sample_ = 1 if (treated_list==1 | enlargedcontrol==1) & basecontrol!=1 
**
preserve
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_e = e(sample)
count if sample1_e==1
count if sample1_e==1 & aggregate_students_origin==0
* 
estimates store l_5
restore
* India
preserve
drop if Origin=="Vietnam" | Origin=="China"
***This is to make sure that institutions from "treated list" that are not treated for India do not end up being considered as control institutions (same for China and Vietnam below)
replace sample_ = 0 if treated_list==1 & dumvarIndia_treatlist==. 
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_eI = e(sample)
count if sample1_eI==1
count if sample1_eI==1 & aggregate_students_origin==0
* 
estimates store l_6
restore 
* China
preserve
drop if Origin=="Vietnam" | Origin=="India"
replace sample_ = 0 if treated_list==1 & dumvarChina_treatlist==. 
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_eC = e(sample)
count if sample1_eC==1
count if sample1_eC==1 & aggregate_students_origin==0
* 
estimates store l_7
restore
* Vietnam
preserve
drop if Origin=="China" | Origin=="India"
replace sample_ = 0 if treated_list==1 & dumvarVietnam_treatlist==. 
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_eV = e(sample)
count if sample1_eV==1
count if sample1_eV==1 & aggregate_students_origin==0
* 
estimates store l_8
restore

 
 
 
********************************
***** Estimates - Table 7 ******
********************************
* Robustness Check: Placebo Test
********************************
clear
use "$dataPlacebo.dta"

*****
ppml_panel_sg aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, ex(Origin) im(Name_Institution) y(year) cluster(ji)
gen sample_ppml_pl = e(sample)
ppmlhdfe aggregate_students_origin_pl treatment_var if sample_ppml_pl==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store y_1
gen sample_ppml_pl_all = e(sample)
count if aggregate_students_origin_pl==0 & sample_ppml_pl_all==1
*****
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppmlhdfe aggregate_students_origin_pl treatment_var if sample_ppml_pl==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store y_2
restore 
preserve
drop if Origin=="Vietnam" | Origin=="India"
ppmlhdfe aggregate_students_origin_pl treatment_var if sample_ppml_pl==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store y_3
restore 
preserve
drop if Origin=="India" | Origin=="China"
ppmlhdfe aggregate_students_origin_pl treatment_var if sample_ppml_pl==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store y_4
restore 
*****
esttab y_* using baseline_placebo.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.001) replace





***********
* Table 8 *
***********

** Mechanisms - Applications (PRE-2014) **
 

use "$dataApplications.dta", clear


gen Approval_Rate = (Appapproved_new/Apptotal_new)*100
ppml_panel_sg Appapproved_new treatment_var if sample_==1 & year>=2003 & year<=2013, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)


gen sample_ppml = e(sample)
* Aggregate
preserve
ppml_panel_sg aggregate_students_origin treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_1
ppml_panel_sg Apptotal_new treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_2
ppml_panel_sg Approval_Rate treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_3
restore
*India / Country by Country
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppml_panel_sg aggregate_students_origin treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_4
ppml_panel_sg Apptotal_new treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_5
ppml_panel_sg Approval_Rate treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_6
restore 
*China / Country by Country
preserve
drop if Origin=="Vietnam" | Origin=="India"
ppml_panel_sg aggregate_students_origin treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_7
ppml_panel_sg Apptotal_new treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_8
ppml_panel_sg Approval_Rate treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store ki_9
restore
*
esttab ki_* using Application_till2013.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace
 

 
***********
* Table 9 *  
***********
 clear all

use "$dataApplications.dta", clear

qui ppml_panel_sg Appapproved_new treatment_var if sample_==1 & year>=2003 & year<=2013, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
gen sample_ppml = e(sample)

**TEST WITH BASELINE COUNTERFACTUAL - 

*India / Country by Country
preserve
drop if Origin=="Vietnam" | Origin=="China"
**REG FOR - (Column 1): Baseline (from Table 7 on mechanism)
ppml_panel_sg Apptotal_new treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store rr_1
restore

**TEST WITH UNI counterfactual 
replace sample_ = 0
replace sample_ = 1 if (treated_list==1 | enlargedcontrol==1) & basecontrol!=1 
drop sample_ppml
qui ppml_panel_sg Appapproved_new treatment_var if sample_==1 & year>=2003 & year<=2013, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
gen sample_ppml = e(sample)

*India / Country by Country
preserve
drop if Origin=="Vietnam" | Origin=="China"
**REG FOR - (Column 2)
ppml_panel_sg Apptotal_new treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store rr_2
restore 

**TEST WITH COLLEGES ONLY
drop sample_ppml
replace sample_ = 0
replace sample_ = 1 if treated_list==1 | controlgroup2==1 
replace sample_ = 0 if enlargedcontrol==0
replace sample_ = 0 if controlbis==1

qui ppml_panel_sg Appapproved_new treatment_var if sample_==1 & year>=2003 & year<=2013, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
gen sample_ppml = e(sample)

*India / Country by Country
preserve
drop if Origin=="Vietnam" | Origin=="China"
**REG FOR - (Column 3)
ppml_panel_sg Apptotal_new treatment_var if sample_ppml==1, ex(i_) im(Insitution_Code_5Digit) y(year) cluster(ji)
estimates store rr_3
restore
*
esttab rr_* using Table_9.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace



*******************
* Table 10 and 11 *
*******************
* Crowding In/Out 
*--------------------------------
clear

use "$dataCrowding_Out.dta", clear

***Generate total students by summing international and all (naturalized + canadian born students)
gen totalstudent=aggregate_students_foreign+Canadian_students
gen log_canadians = ln(Canadian_students)
gen log_forstud = ln(aggregate_students_foreign)
* Share Canadians
gen share_canadians = (Canadian_students)/totalstudent
gen log_share_can = ln(share_canadians)

*-----------------------------------------------
* Add Province*Year FEs to control for amenities
egen province_year = group(Province year)

* #### Table CROWDING OUT Share <=2017 #### 

* Crowding out on Natives (Share)
*drop sample_co_nt
reghdfe log_share_can log_forstud if sample_==1 & year<=2017 & year>=2003, absorb(Insitution_Code_5Digit province_year) cluster(Insitution_Code_5Digit) 
gen sample_co_nt = e(sample)
estimates store das_1
ppmlhdfe share_canadians log_forstud if sample_co_nt==1, absorb(Insitution_Code_5Digit province_year) cluster(Insitution_Code_5Digit) 
estimates store das_2
ivreghdfe log_share_can (log_forstud = treatment_var_) if sample_co_nt==1, absorb(Insitution_Code_5Digit province_year) cluster(Insitution_Code_5Digit) first
estimates store das_3
ivpoisson cfunction share_canadians (log_forstud = treatment_var_) i.province_year i.Insitution_Code_5Digit if sample_co_nt==1, vce (cluster Insitution_Code_5Digit)
estimates store das_4
*Reduced form test
reghdfe log_share_can treatment_var_ if sample_co_nt==1, absorb(Insitution_Code_5Digit province_year) cluster(Insitution_Code_5Digit) 
estimates store das_5
ppmlhdfe share_canadians treatment_var_ if sample_co_nt==1, absorb(Insitution_Code_5Digit province_year) cluster(Insitution_Code_5Digit) 
estimates store das_6
esttab das_* using crowding_out_1.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) keep(treatment_var_ log_forstud) replace


* #### Table CROWDING OUT Numbers <=2017 ####

* Crowding Out on Natives (Number) and Non-Treated Foreign Students
reghdfe log_canadians log_forstud if sample_co_nt==1, absorb(Insitution_Code_5Digit province_year) cluster(Insitution_Code_5Digit)
estimates store dasi_1
ivreghdfe log_canadians (log_forstud = treatment_var_) if sample_co_nt==1, absorb(Insitution_Code_5Digit province_year) cluster(Insitution_Code_5Digit) first
estimates store dasi_2
ivpoisson cfunction Canadian_students (log_forstud = treatment_var_) i.province_year i.Insitution_Code_5Digit if sample_co_nt==1, vce (cluster Insitution_Code_5Digit)
estimates store dasi_3
* Non-Trated Students
gen non_treated_studs = (aggregate_students_foreign - aggregate_students_foreign_CHI - aggregate_students_foreign_IND - aggregate_students_foreign_VNM)
gen log_non_treated_studs = ln(non_treated_studs)
* * * * * *
gen treated_studs = (aggregate_students_foreign_CHI + aggregate_students_foreign_IND + aggregate_students_foreign_VNM)
gen log_treated_studs = ln(treated_studs)
* Adjustment to keep the samples comparable
replace log_treated_studs = ln(1+treated_studs)
replace log_non_treated_studs = ln(1+non_treated_studs)
replace log_canadians = ln(1+Canadian_students)
* * * * * * * * * * * *
reghdfe log_non_treated_studs log_treated_studs if sample_co_nt==1, absorb(Insitution_Code_5Digit province_year) cluster(Insitution_Code_5Digit)
estimates store dasi_4
ivreghdfe log_non_treated_studs log_canadians (log_treated_studs = treatment_var_) if sample_co_nt==1, absorb(Insitution_Code_5Digit province_year) cluster(Insitution_Code_5Digit) first
estimates store dasi_5
ivpoisson cfunction non_treated_studs log_canadians (log_treated_studs = treatment_var_) i.province_year i.Insitution_Code_5Digit if sample_co_nt==1, vce (cluster Insitution_Code_5Digit)
estimates store dasi_6
esttab dasi_* using crowding_out_2.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) keep(treatment_var_ log_forstud log_treated_studs) replace


***********************************************************************************
************************** APPENDIX************************************************
***********************************************************************************

* Table 17		


use "$dataFinalmaster.dta", clear


***** Defining Synthetic control groups generated using the synth package on Stata  

gen synChina=1 if dumvarChina_treatlist==1 | Insitution_Code_5Digit==59002 | Insitution_Code_5Digit==48009 | Insitution_Code_5Digit==48023 | Insitution_Code_5Digit==13002 | Insitution_Code_5Digit==48026  | Insitution_Code_5Digit==24083
gen synIndia=1 if dumvarIndia_treatlist==1 | Insitution_Code_5Digit==12003 | Insitution_Code_5Digit==12004 
gen synVietnam=1 if dumvarVietnam_treatlist==1 | Insitution_Code_5Digit==59002 | Insitution_Code_5Digit==13002  | Insitution_Code_5Digit==48015 | Insitution_Code_5Digit==46001
* India
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppmlhdfe aggregate_students_origin treatment_var if synIndia==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_I = e(sample)
count if sample1_I==1 
count if sample1_I==1 & aggregate_students_origin==0
* 
estimates store r_1
restore 
* China
preserve
drop if Origin=="Vietnam" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if synChina==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_C = e(sample)
count if sample1_C==1
count if sample1_C==1 & aggregate_students_origin==0
* 
estimates store r_2
restore
* Vietnam
preserve
drop if Origin=="China" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if synVietnam==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample1_V = e(sample)
count if sample1_V==1
count if sample1_V==1 & aggregate_students_origin==0
*
estimates store r_3
restore
esttab r_* using synth.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace




************************************************************
* Estimates - Table 19
************************************************************
* Robustness Check - Excluding Data on Approved Applications
************************************************************

use "$dataFinalmaster.dta", clear

*Drop institutions with application data
replace sample_=0
replace sample_ = 1 if treated_list==1 | controlgroup2==1
replace sample_=0 if Name_Institution=="Cambrian College" 
replace sample_=0 if Name_Institution=="Centennial College of Applied Arts and Technology" 
replace sample_=0 if Name_Institution=="Conestoga College of Applied Arts and Technology" 
replace sample_=0 if Name_Institution=="Confederation College of Applied Arts and Technology" 
replace sample_=0 if Name_Institution=="Georgian College of Applied Arts and Technology" 
replace sample_=0 if Name_Institution=="Loyalist College of Applied Arts and Technology" 
replace sample_=0 if Name_Institution=="Mohawk College of Applied Arts and Technology" 
replace sample_=0 if Name_Institution=="Lambton College of Applied Arts and Technology" 
replace sample_=0 if Name_Institution=="St. Lawrence College of Applied Arts and Technology - Parent Institution" 
replace sample_=0 if Name_Institution=="Sault College of Applied Arts and Technology - Parent Institution" 
replace sample_=0 if Name_Institution=="Douglas College"
replace sample_=0 if Name_Institution=="Red River College - Parent Institution" 
replace sample_=0 if Name_Institution=="Columbia College"
replace sample_=0 if Name_Institution=="Booth University College"
replace sample_=0 if Name_Institution=="University College of the North"


* Aggregate 
preserve
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store d_1
restore 
* India
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store d_2
restore 
* China
preserve
drop if Origin=="Vietnam" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store d_3
restore 
* Vietnam
preserve
drop if Origin=="China" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
estimates store d_4
restore 
esttab d_* using baseline_compare.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace


************************************************
* Estimates - Table 20 /  Pre-2015 effect of SPP 
************************************************
* Robustness Check - China vs India PRE 2015
********************************************

use "$dataFinalmaster.dta", clear

ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2014, absorb(it jt ji) cluster(ji)
gen sample_ppml = e(sample)
* 
preserve
drop if Origin=="Vietnam" | Origin=="China"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2014, absorb(it jt ji) cluster(ji)
estimates store di_1
restore
preserve
drop if Origin=="Vietnam" | Origin=="India"
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2014, absorb(it jt ji) cluster(ji)
estimates store di_2
restore
esttab di_* using pre_2015.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace


*********************************
* Table 21: Alternative Estimators (with HDFEs)
* OLS no-zeros / Scaled OLS / OLS with zeros replaced by inverse hyperbolic sine transformation 
*********************************

use "$dataFinalmaster.dta", clear

gen ihs_aggregate_students_origin = log( aggregate_students_origin + sqrt(aggregate_students_origin^2+1) )
gen log_aggregate_students_origin = ln(1 + aggregate_students_origin)
gen log_aggregate_students_origin_ = ln(aggregate_students_origin)

* OLS - Log Linear * 
* * * * * * * * * * * * * * * * * // * * * * * * * * * * * * * * * 
* triple-diff
ppmlhdfe aggregate_students_origin treatment_var if sample_==1 & year>=2003 & year<=2017, absorb(it jt ji) cluster(ji)
gen sample_ppml = e(sample)
reghdfe log_aggregate_students_origin_ treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store ke_1
* India
preserve
drop if Origin=="Vietnam" | Origin=="China"
reghdfe log_aggregate_students_origin_ treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store ke_2
restore
* China
preserve
drop if Origin=="Vietnam" | Origin=="India"
reghdfe log_aggregate_students_origin_ treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store ke_3
restore
* Vietnam
preserve
drop if Origin=="India" | Origin=="China"
reghdfe log_aggregate_students_origin_ treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store ke_4
restore
* double-diff
reghdfe log_aggregate_students_origin_ treatment_var if sample_ppml==1 & Origin=="India", absorb(Insitution_Code_5Digit year) cluster(Insitution_Code_5Digit)
estimates store ke_5
reghdfe log_aggregate_students_origin_ treatment_var if sample_ppml==1 & Origin=="China", absorb(Insitution_Code_5Digit year) cluster(Insitution_Code_5Digit)
estimates store ke_6
reghdfe log_aggregate_students_origin_ treatment_var if sample_ppml==1 & Origin=="Vietnam", absorb(Insitution_Code_5Digit year) cluster(Insitution_Code_5Digit)
estimates store ke_7
esttab ke_* using alternative_estimators_OLS.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace

* IHS - Log *
*************
* triple-diff
reghdfe ihs_aggregate_students_origin treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store ka_1
* India
preserve
drop if Origin=="Vietnam" | Origin=="China"
reghdfe ihs_aggregate_students_origin treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store ka_2
restore
* China
preserve
drop if Origin=="Vietnam" | Origin=="India"
reghdfe ihs_aggregate_students_origin treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store ka_3
restore
* Vietnam
preserve
drop if Origin=="India" | Origin=="China"
reghdfe ihs_aggregate_students_origin treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store ka_4
restore
* double-diff
reghdfe ihs_aggregate_students_origin treatment_var if sample_ppml==1 & Origin=="India", absorb(Insitution_Code_5Digit year) cluster(Insitution_Code_5Digit)
estimates store ka_5
reghdfe ihs_aggregate_students_origin treatment_var if sample_ppml==1 & Origin=="China", absorb(Insitution_Code_5Digit year) cluster(Insitution_Code_5Digit)
estimates store ka_6
reghdfe ihs_aggregate_students_origin treatment_var if sample_ppml==1 & Origin=="Vietnam", absorb(Insitution_Code_5Digit year) cluster(Insitution_Code_5Digit)
estimates store ka_7
esttab ka_* using alternative_estimators_IHS.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace


* Linear *
**********
* triple-diff
reghdfe aggregate_students_origin treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store kes_1
* India
preserve
drop if Origin=="Vietnam" | Origin=="China"
reghdfe aggregate_students_origin treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store kes_2
restore
* China
preserve
drop if Origin=="Vietnam" | Origin=="India"
reghdfe aggregate_students_origin treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store kes_3
restore
* Vietnam
preserve
drop if Origin=="India" | Origin=="China"
reghdfe aggregate_students_origin treatment_var if sample_ppml==1, absorb(it jt ji) cluster(ji)
estimates store kes_4
restore
* double-diff
reghdfe aggregate_students_origin treatment_var if sample_ppml==1 & Origin=="India", absorb(Insitution_Code_5Digit year) cluster(Insitution_Code_5Digit)
estimates store kes_5
reghdfe aggregate_students_origin treatment_var if sample_ppml==1 & Origin=="China", absorb(Insitution_Code_5Digit year) cluster(Insitution_Code_5Digit)
estimates store kes_6
reghdfe aggregate_students_origin treatment_var if sample_ppml==1 & Origin=="Vietnam", absorb(Insitution_Code_5Digit year) cluster(Insitution_Code_5Digit)
estimates store kes_7
esttab kes_* using alternative_estimators_OLSlinear.rtf, se ar2 star(* 0.10 ** 0.05 *** 0.01) replace








